/**
 * 用于页面中文字显示的优化 配合layui中的badge（徽章）使用
 */
layui.define(['form', 'element'], function (exports) {
    var $ = layui.jquery;
    var form = layui.form;
    var element = layui.element;

    var mode = {
        0: 'layui-badge',
        1: 'layui-badge-dot',
        2: 'layui-badge-rim'
    }

    var defaultColor = {
        red: 'layui-badge-red',
        yellow: 'layui-badge-yellow',
        green: 'layui-badge-green',
        blue: 'layui-badge-blue',
        black: 'layui-bg-black',
        gray: 'layui-badge-gray',
    }

    var badgeX = {
        init: function (str, color, icon) {
            let colorValue = defaultColor[color];
            if (!colorValue) {
                colorValue = defaultColor.red;
            }
            let badgeValue = mode[0];
            if (icon) {
                return '<span class=" ' + badgeValue + ' ' + colorValue + '"><i class="layui-icon layui-icon-' + icon + '"></i> ' + str + '</span>'
            } else {
                return '<span class=" ' + badgeValue + ' ' + colorValue + '">' + str + '</span>'
            }

        },
        initRed: function (str, icon) {
            return this.init(str, 'red', icon);
        },
        initYellow: function (str, icon) {
            return this.init(str, 'yellow', icon);
        },
        initGreen: function (str, icon) {
            return this.init(str, 'green', icon);
        },
        initBlue: function (str, icon) {
            return this.init(str, 'blue', icon);
        },
        initBlack: function (str, icon) {
            return this.init(str, 'black', icon);
        },
        initGray: function (str, icon) {
            return this.init(str, 'gray', icon);
        },
        initYes: function () {
            return this.initGreen('', 'ok');
        },
        initNo: function () {
            return this.initRed('', 'close');
        }
    };

    badgeX.init();
    exports('badgeX', badgeX);
});
